package eu.flatworld.android.ontop;

import java.util.List;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import eu.flatworld.android.ontop.db.ChecklistItem;

public class ChecklistItemAdapter extends ArrayAdapter <ChecklistItem> {
	ColorStateList defaultTextColors;

	public ChecklistItemAdapter(Context context, List<ChecklistItem> objects) {
		super(context, android.R.layout.simple_list_item_1, objects);
		
		TextView tv = (TextView) TextView.inflate(context,
				android.R.layout.simple_list_item_1, null);
		defaultTextColors = tv.getTextColors();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
        if (v == null) {
            v = super.getView(position, convertView, parent);
        }
        ChecklistItem ci = getItem(position);
        TextView tv = (TextView) v;
        tv.setText(ci.getName());
        
        if (ci.isChecked() == false) {
			tv.setTextColor(defaultTextColors.getDefaultColor());
			tv.setPaintFlags(Paint.ANTI_ALIAS_FLAG);
		} else {
			tv.setTextColor(Color.DKGRAY);
			tv.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG
					| Paint.ANTI_ALIAS_FLAG);
		}
        return v;
	}
}
